using System.Diagnostics;
using Crusades.Arrows;
using Crusades.Helpers;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Crusades_UT.Helpers {
  [TestClass]
  public class Bezier_UT {
    private Vector[] controlPoints;

    [TestInitialize]
    public void Setup() {
      var P0 = new Vector(13, 159);
      var P1 = new Vector(26, 41);
      var P2 = new Vector(680, 272);
      var P3 = new Vector(575, 155);
      controlPoints = new[]{P0,P1,P2,P3};
    }

    [TestMethod]
    public void canCreate() {
      Bezier bezier = new Bezier(controlPoints);
      Assert.IsNotNull(bezier);
    }

    [TestMethod]
    public void canGetControlPointsBack(){
      Bezier bezier = new Bezier(controlPoints);
      Assert.AreEqual(controlPoints,bezier.ControlPoints);
    }

    [TestMethod]
    public void canGetDataString(){
      Bezier bezier = new Bezier(controlPoints);
      const string expected = "Data=\"M13,159 C26,41 680,272 575,155\"";
      Assert.AreEqual(expected,bezier.ToData());
      
    }


    [TestMethod]
    public void areEqualIFFControlPointsAreEqual(){
      Bezier first = new Bezier(new []{new Vector(1,1), new Vector(2,2),new Vector(3,3),new Vector(4,4) });
      Bezier second = new Bezier(controlPoints);
      Bezier third  = new Bezier(controlPoints);

      Assert.AreEqual(second,third);
      Assert.AreNotEqual(first,second);
    }

    [TestMethod]
    public void canSplitToT(){
      Bezier bezier = new Bezier(controlPoints);
      Bezier split = bezier.SplitTo(.35);
      Vector[] expected = new[]{new Vector(13,159),  new Vector(17.55,117.7), new Vector(100.6225,119.1525), 
                                new Vector(202.1925,133.473625)};
      Bezier expectedBezier = new Bezier(expected);
      Assert.IsNotNull(split);
      Assert.AreEqual(expectedBezier,split);
      Debug.WriteLine(split.ToData());
    }


  }

}